#include <iostream>
using namespace std;
#define pi 3.14

class shape
{
public:
    virtual ~shape(){}
    virtual double perimeter()=0;
    virtual double area() = 0;
};

class triangle :public shape
{
public:
    triangle(){
        cout<<"输入等边三角形边长:";
        cin>>this->len;
    }
    virtual ~triangle(){

    }
    double perimeter(){
        return 3*this->len;
    }
    double area(){
        return this->len*this->len*1.71/4;
    }

private:
    int len;

};

class rectangle :public shape
{
public:
    rectangle(){
        cout<<"输入长方形长:";
        cin>>this->len;
        cout<<"输入长方形宽:";
        cin>>this->len1;

    }
    virtual ~rectangle(){

    }
    double perimeter(){
        return 2*(this->len+this->len1);
    }
    double area(){
        return this->len*this->len1;
    }

private:
    int len;
    int len1;

};

class square :public shape
{
public:
    square(){
        cout<<"输入正方形边长:";
        cin>>this->len;
    }
    virtual ~square(){

    }
    double perimeter(){
        return 4*this->len;
    }
    double area(){
        return this->len*this->len;
    }

private:
    int len;

};

class circle :public shape
{
public:
    circle(){
        cout<<"输入圆形的半径:";
        cin>>this->r;
    }
    virtual ~circle(){

    }
    double perimeter(){
        return 2*pi*this->r;
    }
    double area(){
        return pi*this->r*this->r;
    }

private:
    int r;

};

int main()
{
    shape *tri=new triangle;
    cout<<"等边三角形周长:"<<tri->perimeter()<<endl;
    cout<<"等边三角形面积:"<<tri->area()<<endl;
    shape *cri=new circle;
    cout<<"圆形周长:"<<cri->perimeter()<<endl;
    cout<<"圆形面积:"<<cri->area()<<endl;
    shape *squ=new square;
    cout<<"正方形周长:"<<squ->perimeter()<<endl;
    cout<<"正方形面积:"<<squ->area()<<endl;
    shape *rec=new rectangle;
    cout<<"长方形周长:"<<rec->perimeter()<<endl;
    cout<<"长方形面积:"<<rec->area()<<endl;
    delete squ;
    delete tri;
    delete cri;
    delete rec;
}
